﻿@model OpenAuth.App.ViewModel.UserView
@{
    ViewBag.Title = "title";
    Layout = null;
}

<div class="bjui-pageContent">
    <form action="/UserManager/Add" class="pageForm" data-toggle="validate">
        <table class="table table-condensed table-hover">
            <tbody>

                <tr>
                    <td>
                        @Html.HiddenFor(m => m.CreateTime)
                        @Html.HiddenFor(m => m.Id)
                        <label for="Account" class="control-label x90">用户账号：</label>
                        <input type="text" name="Account" id="Account" value="@Model.Account"
                               data-rule="required" size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Name" class="control-label x90">姓名/昵称：</label>
                        <input type="text" name="Name" id="Name" value="@Model.Name" size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Organizations" class="control-label x90">所属机构：</label>
                        <input id="OrganizationIds" name="OrganizationIds" value="@Model.OrganizationIds" style="display: none" />
                        <input type="text" name="Organizations" id="Organizations"
                               data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.Organizations">
                        <ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Status" class="control-label x85">设置状态：</label>

                        <select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
                            <option value="0" @if (Model.Status == 0) { <text> selected="selected" </text>     }>正常</option>
                            <option value="1" @if (Model.Status == 1) { <text> selected="selected" </text>     }>禁用</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="Sex" class="control-label x85">性别：</label>

                        <select name="Sex" id="Sex" data-toggle="selectpicker" data-rule="required">
                            <option value="0" @if (Model.Status == 0) { <text> selected="selected" </text>      }>男</option>
                            <option value="1" @if (Model.Status == 1) { <text> selected="selected" </text>      }>女</option>
                        </select>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close">关闭</button></li>
        <li><button type="submit" class="btn-green">保存</button></li>
    </ul>
</div>

<script type="text/javascript">

    var ztree = function () {
        var orgName = $("#Organizations");
        var orgIds = $("#OrganizationIds");
        var zTreeObj;
        var setting = {
            view: {
                selectedMulti: false
            },
            check: {
                enable: true,
                chkStyle: "checkbox",
                chkboxType: { "Y": "", "N": "" } //去掉勾选时级联
            },
            data: {
                key: {
                    name: 'Name',
                    title: 'Name'
                },
                simpleData: {
                    enable: true,
                    idKey: 'Id',
                    pIdKey: 'ParentId',
                    rootPId: 'null'
                }
            },
            callback: {
                onClick: zTreeOnClick,
                onCheck: zTreeCheck
            }
        };

        function zTreeCheck(event, treeId, treeNode) {
            var nodes = zTreeObj.getCheckedNodes(true);
            var ids = nodes.map(function (e) { return e.Id; }).join(",");
            var names = nodes.map(function (e) { return e.Name; }).join(",");

            orgName.val(names);
            orgIds.val(ids);
        }
        function zTreeOnClick(event, treeId, treeNode) {
            zTreeObj.checkNode(treeNode, !treeNode.checked, true, true);
            event.preventDefault();
        }

        $.getJSON('/OrgManager/LoadOrg', function (json) {
            zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
            var orgstr = orgIds.val();
            if (orgstr != '') {
                var nodeIds = orgstr.split(',');
                $.each(nodeIds, function () {
                    var node = zTreeObj.getNodeByParam("Id", this, null);
                    zTreeObj.checkNode(node, true, true);
                });
            }
            zTreeObj.expandAll(true);
        });
    }();


</script>